<?php
	include "../public/commom/config.php";
	include "../public/commom/commom.php";
	
	if($_GET) {
		$class_id = $_GET["class_id"];
		
		$sql = "SELECT * FROM class WHERE id = $class_id";
		
		$result = mysqli_query($conn, $sql);
		
		while($row = mysqli_fetch_array($result)) {
			$cname = $row["name"];
		}
		
		if(isset($_GET["brand_id"])) {
			$brand_id = $_GET["brand_id"];
			
			$sql = "SELECT * FROM brand WHERE id = $brand_id";
			
			$result = mysqli_query($conn, $sql);
			
			while($row = mysqli_fetch_array($result)) {
				$bname = $row["name"];
			}
		}
	}
?>

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>商城 - <?php echo $cname; ?></title>
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="public/index.css"/>
	</head>

	<body>
		<div id="header">
			<div style="height: 40px;" class="container">
				<div class="header-left">
					<a href="index.php">商城</a>
				</div>
				<div class="header-right">
					<a href="registered.php">注册</a>
					<a href="login.php">登录</a>
					<a href="personal.php">个人中心</a>
					<a href="javascript:;">查看订单</a>
					<a href="cart/index.php">购物车</a>
				</div>
			</div>
		</div>
		<div id="main">
			<div class="container">
				<div class="status">
					<a href="index.php">首页</a> >> <a href="more.php?class_id=<?php echo $class_id; ?>"><?php echo $cname; ?></a><?php if(isset($bname)) {echo " >> " . $bname; }?>
				</div>
				<div class="more">
					<div class="more-products">
						<div class="more-title">
							<h2>手机</h2>
						</div>
						<div class="more-brand">
							<?php
								if($_GET) {
									$sql = "SELECT * FROM brand WHERE class_id = $class_id";
									
									$result = mysqli_query($conn, $sql);
									
									$firstBranid = 0;
									$i = 0;
									
									while($row = mysqli_fetch_array($result)) {
										if($i == 0) {
											$firstBranid = $row["id"];
											$i++;
										}
										echo "<a href='more.php?class_id=" . $class_id . "&brand_id=" . $row["id"] . "'>" . $row["name"] . " </a>";
									}
								}
							?>
						</div>
						<ul>
							<?php
								if($_GET) {
									$brand_id = isset($_GET["brand_id"]) ? $_GET["brand_id"] : $firstBranid;
									
									if(isset($_GET["brand_id"])) {
										$sql = "SELECT shop.* FROM shop LEFT JOIN brand ON (shop.brand_id = brand.id) WHERE brand.id = $brand_id";
									}else {
										$sql = "SELECT shop.* FROM shop LEFT JOIN brand ON (shop.brand_id = brand.id) WHERE brand.class_id = $class_id";
									}
									
									$result = mysqli_query($conn, $sql);
									
									while($row = mysqli_fetch_array($result)) {
										echo "<li>
												<a href='details.php?shop_id=" . $row["id"] . "&class_id=" . $class_id . "'><img src='" . $imgPath . $row["img"] . "'/></a>
												<h3><a href='details.php?shop_id=" . $row["id"] . "&class_id=" . $class_id . "'>" . $row["name"] . "</a></h3>
												<p class='more-describe'>" . $row["describe"] . "</p>
												<p class='more-price'><strong>" . $row["pice"] . "</strong>元起</p>
											</li>";
									}
									
									mysqli_close($conn);
								}
							?>
						</ul>
					</div>
				</div>
			</div>
		</div>
	</body>

</html>